<template>
  <div>
    <!-- 展示数据 -->
    <el-table :data="pageBean.records" style="width: 100%">
      <el-table-column prop="username" label="姓名" width="180" />
      <el-table-column prop="number" label="工号" width="180" />
    </el-table>  
    <!-- 展示页码 -->
    <div class="demo-pagination-block">
    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[2,5,8]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageBean.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</div>
</template>

<script setup>
import { ref, reactive } from 'vue';
  import axios from 'axios';
  import { onMounted } from 'vue'
  const pageBean = reactive({});
  const admemployee = reactive({});
  const currentPage = ref(1)
  const pageSize = ref(2)
  
  onMounted(() => {
    getAll();
  })
  // 获取全部
  function getAll(){
    axios.post(`/getall/${currentPage.value}/${pageSize.value}`,admemployee).then((resp) => {
      if(resp.data.code==200){
        console.log(resp.data.data)
        Object.assign(pageBean, resp.data.data);
      }
    });
  }
  // 分页
  function handleSizeChange(val) {
    console.log(`每页 ${val} 条`);
    //  重新查询
    pageSize.value = val;
    getAll();
  }
  function handleCurrentChange(val) {
    console.log(`当前页: ${val}`);
    //  重新查询
    currentPage.value = val;
    getAll();
  }
</script>

<style scoped>
.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}
</style>